package com.qcby.shujia.demo.util;

import com.qcby.shujia.demo.entity.User;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @className: TokenUtil
 * @description: 令牌
 * @author: whz
 * @date: 2021/10/10
 **/
public class TokenUtil {
    /**
     * @param: null
     * @description: 存储所有已经登录的用户信息及其令牌
     * @return:
     * @author: whz
     * @date: 2021/10/10
     */
    public static Map<String,User> tokenMap=new HashMap<>();


   private TokenUtil(){
        //工具类，不可new
    }

    public static String getToken(User user){

       String token= UUID.randomUUID().toString().replaceAll("-", "");
       tokenMap.put(token, user);
       return token;
    }

    public static User getUser(String token){
        return tokenMap.get(token);
    }

    public static Boolean verToken(String token){
        return tokenMap.get(token)==null;
    }

}
